<?php

function books_class($tid) {

	global $user;
	
	
	$output = '<div id="dlg"></div><div id="dlgs"></div>';
	
	$output .='<div class="item-list-box"><div class="holder"><div class="frame">';
	
	$term = taxonomy_term_load($tid);
	$output .='<div class="heading"><h2>'. $term->name .'</h2></div>';
	
	$output .='<div id="books-items">';
	
	$query = db_select('node','n')
				->extend('PagerDefault')
				->limit(10); 
	$query->fields('n', array('nid'))
    		->condition('n.type', 'book')
			->orderBy('n.created', 'DESC');
  	$nids = $query->execute()->fetchCol();
	
	$html = '';
	$row = array();
	foreach($nids as $value){
		$node = node_load($value);
		$cover = field_get_items('node', $node, 'field_book_cover');
		$path = node_uri($node);
		
		$isbn = field_get_items('node', $node, 'field_book_sin');
		$author = field_get_items('node', $node, 'field_book_author');
		$pub = field_get_items('node', $node, 'field_book_public');
		$bind = field_get_items('node', $node, 'field_book_bind');
		$body = field_get_items('node', $node, 'body');
		
		$html .= '<div class="book-item-row">';

		

  		$html .= '<div class="book-cover book-item"><a href="'. url($path['path']) .'"><img src="'. image_style_url('width_117', $cover[0]['uri']) .'"></a>'; 
  		if (user_is_logged_in()) {
        	$html .= '<input class="book-collect book-button" type="submit" 
        				value="收藏" nid="'.$node->nid.'">';
        				
        	$roles = array_keys($user->roles);
        	if(in_array(3, $roles) || in_array(4, $roles)) {
        		$html .='<input class="book-s book-button" 
        					type="submit" value="订阅" nid="'.$node->nid.'">';
        	}
		}
        $html .= '</div>';
  		$html .= '<div class="book-item"><h3>'. l($node->title, url($path['path'])) .'</h3>
		<p><strong>书号:</strong>'. $isbn[0]['value'] .'</p>
		<p><strong>作者:</strong>'. $author[0]['value'] .'</p>
		<p><strong>出版社:</strong>'. $pub[0]['value'] .'</p>
		<p><strong>上架日期:</strong>'. format_date($node->created, 'custom', 'Y-m-d') .'</p>
		</div>';
  	$html .= '<div class="book-body book-item"><p>' . drupal_substr(drupal_html_to_text($body[0]['value']), 0, 100) .'...</p></div>';
		$html .= '<div class="clearfix"></div></div>';
	}
	$output .= $html;
	
	
	$output .='</div>';
	$output .= theme('pager');
	$output .='</div></div></div>';	
	return $output;

}

